#include<iostream>
#include<assert.h>
using namespace std;
template<class T>
class vector
{
public:
	vector()
		:_a(nullptr)
		,_size(0)
		,_capacity(0)
	{} 
	
	~vector() 
	{
		delete[] _a;
		_a = nullptr;
		_size = _capacity = 0; 
	}

	void push_back(const T& x);
	
	void pop_back();
	size_t size()
	{
		return _size;
	}
	T& operator[](size_t pos)
	{
		assert(pos < _size);
		return _a[pos];
	}
private:
	T* _a;
	size_t _size;
	size_t _capacity;
};


template<class T>
void vector<T>::push_back(const T& x)
{
	if (_size == _capacity) { 
	    size_t newcapacity = _capacity == 0 ? 4 : 2 * _capacity;
		T* temp = new T[newcapacity];
		if (_a) {
			memcpy(temp, _a, _size * sizeof(T));
			delete[] _a;
		}
		_a = temp; 
		_capacity = newcapacity;
	}
	_a[_size] = x;  
	_size++;
}

template<class T>
void vector<T>::pop_back()
{
	assert(_size > 0);
	--_size;
}
int main()
{
	vector<int>v;
	v.push_back(1);
	v.push_back(2);
	v.push_back(3);
	v.push_back(4);
	v.pop_back();
	for (size_t i = 0; i < v.size(); i++) {
		v[i] *= 2;
	}
	for (size_t i = 0; i < v.size(); i++) {
		cout << v[i] << " ";
	}
	cout << endl;
	return 0;
}